
use "allstudies_cites2.dta", clear 

* Dropping the ordered and multinomial models, since we won't me able to FE them anyways.
drop if method_orig == "mlogit"
drop if method_orig == "ologit"

* One study, Vreeland, had a model with and without clogit/FE.  To avoid duplications, we're dropping the clogit one
drop if pval_cites_orig!=. & pval_cites_noth==.

* Sorting the replications and numbering them, according to the baseline replication p values
sort pval_cites_orig
gen id = _n

* Rename
rename pval_match pval_cites_match


*** "Descriptives of false positives"
foreach var in pval_cites_orig pval_cites_noth pval_cites_fe pval_cites_time pval_cites_match{
	di "`var'"
	gen sig_`var' = `var'<=0.10
	replace sig_`var' = . if `var'==.
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
*
foreach var in pval_cites_ct pval_cites_fet pval_cites_yfe pval_cites_cyfe  {
	di "`var'"
	gen sig_`var' = `var'<=0.10
	replace sig_`var' = . if `var'==.
	su sig_`var'
	codebook study if `var'!=.
	}
*
* Which studies had at least one FP?
bysort study: egen anyFP = max(sig_pval_cites_orig)
preserve
duplicates drop study, force
tab anyFP
restore
* Which DV's had at least one FP?
bysort dv_orig: egen anyFP_DV = max(sig_pval_cites_orig)
preserve
duplicates drop dv_orig, force
tab anyFP_DV
restore
* Limited and continuous DVs?
	* Marker for LDV models
gen ldv = 0
replace ldv = 1 if method_orig == "clogit" | method_orig == "logit" | method_orig == "probit" | method_orig == "relogit" | method_orig == "xtlogit" | method_orig == "xtnbreg" | method_orig == "xtpqml"
tab sig_pval_cites_orig if ldv==0
tab sig_pval_cites_orig if ldv==1



* Figure 1: CITES FP's, original replications
* First, find where the vertical line needs to be
tab  sig_pval_cites_orig
su  pval_cites_orig if pval_cites_orig <0.10
su  pval_cites_orig if pval_cites_orig <0.05
su  pval_cites_orig if pval_cites_orig <0.01
* There are 32/95 signficant
twoway scatter  pval_cites_orig id if pval_cites_orig<.10 , xline(25.5) yline(.099) msym(Oh) xtitle("Replication #") ytitle("CITES p-value") ||  scatter  pval_cites_orig id if pval_cites_orig>=.10 , msym(X) xlabel(0(10)100) legend(label(1 "Sig. Result") label(2 "Insig. Result"))
*text( .2 24 "WTO Stops torture" , size(vsmall))
	graph export "reps_cites_orig_rr.eps", as(eps) preview(off) replace




* Marker for whether the study had CFE, splines, YFE, etc
gen sameas = 0
replace sameas = 1 if  b_cites_orig == b_cites_noth
replace sameas = 2 if  b_cites_orig == b_cites_fe
replace sameas = 3 if  b_cites_orig == b_cites_time
replace sameas = 4 if  b_cites_orig == b_cites_fet
replace sameas = 5 if  b_cites_orig == b_cites_ct
replace sameas = 6 if  b_cites_orig == b_cites_yfe
replace sameas = 7 if  b_cites_orig == b_cites_cyfe

* Country FE?
tab sameas if sameas==2 | sameas==4 | sameas==7
* Time based fix?
tab sameas if sameas==3 | sameas==4 | sameas==5 | sameas==6 | sameas==7
* Combo of fixes?
tab sameas if sameas==4 | sameas==7


* Table 1: FP Rates across Orig, Reduced, Country FE, Splines/Trend, Matching
foreach var in pval_cites_orig pval_cites_noth pval_cites_fe pval_cites_time pval_cites_match {
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
* 



* Figure 2: CITES FP's, CFE replications
su  pval_cites_fe if pval_cites_fe <0.10
twoway scatter  pval_cites_fe id if pval_cites_fe<=.10 , xline(25.5) yline(.099) msym(Oh) xtitle("Replication #") ytitle("CITES p-value") ||  scatter  pval_cites_fe id if pval_cites_fe>.10 , msym(X) xlabel(0(10)90) legend(label(1 "Sig. Result") label(2 "Insig. Result"))
	graph export "reps_cites_fe_rr.eps", as(eps) preview(off) replace


* Figure 3: Matching replications
twoway scatter  pval_cites_match id if sig_pval_cites_match==1, xline(25.5) yline(0.099) msym(Oh) xtitle("Replication #") ytitle("CITES p-value") ||  scatter  pval_cites_match id if sig_pval_cites_match==0, msym(X) xlabel(0(10)90) legend(label(1 "Sig. Result") label(2 "Insig. Result"))
*text( .2 24 "WTO Stops torture" , size(vsmall))
	graph export "reps_cites_match_rr.eps", as(eps) preview(off) replace


* Percent reduction in bias, FP and not FP
su bias_match if sig_pval_cites_match==1
su bias_match if sig_pval_cites_match==0
probit sig_pval_cites_match bias_match
logit sig_pval_cites_match bias_match



* Table 2: FP Rates across Country Trends, CT + Country FE, YFE, CFE + YFE
foreach var in pval_cites_ct pval_cites_fet pval_cites_yfe pval_cites_cyfe {
	di "The percent of false positives for `var'"
	su sig_`var'
	tab sig_`var'
	di "The number of studies for `var'"
	codebook study if `var'!=.
	}
* 
